const render = require('koa-art-template');
const path = require("path")
const requireDir = require("require-directory");
const Router = require("koa-router")
const koaBody = require("koa-body");
const static = require("koa-static")
function initProject(app) {
    app.use(koaBody({
        multipart: true,
        formidable: {
            maxFileSize: 200 * 1024 * 1024,
            keepExtensions: true
        }
    }))
    requireDir(module, "../routers", { visit: loadRouters })
    function loadRouters(obj) {
        if (obj instanceof Router) {
            app.use(obj.routes())
        }
    }

    render(app, {
        root: path.join(process.cwd(), 'pages'),
        extname: '.html',
        debug: process.env.NODE_ENV !== 'production'
      });

    app.use(static(path.join(__dirname, "static")))
    app.use(async (ctx, next) => {
        ctx.set("Access-Control-Allow-Origin", "*");
        await next();
    })
}
module.exports = initProject;

// const Router = require("koa-router");
// const requireDir = require("require-directory");
// const render = require('koa-art-template');
// const koaBody = require('koa-body')
// const path = require("path");
// function initProject(app) {
//     app.use(koaBody({
//         multipart: true,
//         formidable: {
//             maxFileSize: 200 * 1024 * 1024,
//             keepExtensions: true
//         }
//     }))
//     requireDir(module, "../routers", { visit: loadRoutes })
//     render(app, {
//         root: path.join(process.cwd(), 'pages'),
//         extname: '.html',
//         debug: process.env.NODE_ENV !== 'production'
//     });
//     function loadRoutes(obj) {
//         console.log(obj instanceof Router);
//         if (obj instanceof Router) {
//             app.use(obj.routes())
//         }
//     }
// }
// module.exports = initProject
